define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trade/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'trade/multi',
                    table: 'trade',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.phone', title: __('Phone')},
                        {field: 'user.name', title: __('Name')},
                        //{field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
                        {field: 'accountId', title: __('AccountId')},
                        {field: 'money', title: __('Money')},
                        //{field: 'valdate', title: __('Valdate')},
                        {field: 'inpdate', title: __('Inptime')},
                        //{field: 'reldate', title: __('Reldate')},
                        //{field: 'inptime', title: __('Inptime')},
                        {field: 'tradNo', title: __('TradNo')},
                        {field: 'oriTradNo', title: __('OriTradNo')},
                        {field: 'typename', title: __('Type'),operate:false},
                        {field: 'description', title: __('Description')},
                        {field: 'balance', title: __('Balance')},
                        //{field: 'forAccountId', title: __('ForAccountId')},
                        {field: 'revind', title: __('Revind'), formatter: Controller.api.formatter.revind},
                        //{field: 'mark', title: __('Mark')},
                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: function (value, row, index) {
                            return  Table.api.formatter.operate.call(this, value, row, index, table);
                        }}
                    ]
                ],
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                revind : function(value,row,index){
                        if(value==1){
                            return '已撤销/冲正';
                        }else{
                            return '正常交易';
                        }
                }
            },
            events: {//绑定事件的方法
                operate: $.extend({
                }, Table.api.events.operate)
            }

        }
    };
    return Controller;
});